import 'package:flutter/material.dart';
import 'package:word_range_client/pages/general/ApplicationInfo.dart';

import '../../pages/general/AccountEdit.dart';
import '../../pages/general/SettingPage.dart';

class Features extends StatefulWidget {
  const Features({super.key});

  @override
  State<Features> createState() => _FeaturesState();
}

class _FeaturesState extends State<Features> {

  void _toAppInfoPage(){
    Navigator.of(context).push(
        MaterialPageRoute(
            builder: (context) => const ApplicationInfo()
        )
    );
  }

  void _toAccountEditPage(){
    Navigator.of(context).push(
        MaterialPageRoute(
            builder: (context) => const AccountEdit()
        )
    );
  }

  void _toSettingPage(){
    Navigator.of(context).push(
        MaterialPageRoute(
            builder: (context) => const SettingPage()
        )
    );
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children:  [
        _FeaturesItem(icon: Icons.account_box,title: "我的账户信息",onPressed: _toAccountEditPage,),
        _FeaturesItem(icon: Icons.settings,title: "设置",onPressed: _toSettingPage,),
        _FeaturesItem(icon: Icons.info,title: "关于APP",onPressed: _toAppInfoPage,),
      ],
    );
  }
}

class _FeaturesItem extends StatelessWidget {
  const _FeaturesItem({super.key, required this.icon, required this.title, this.onPressed});

  final IconData icon;
  final String title;
  final VoidCallback? onPressed;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0, 13, 0, 0),
      child: MaterialButton(
        onPressed: onPressed,
        child: ListTile(
          leading: Icon(icon,size: 27,),
          title: Text(title,style: const TextStyle(fontSize: 17),),
        ),
      ),
    );
  }
}